<extend name="Public/base" />
<block name="style">
    <style type="text/css" >
        .red{color: red;}
        body{ background: #fff;}
        .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12{
            padding-right: 0px;
        }
        .red{
            height: 34px;
            line-height: 34px;
            margin-left: 5px;
        }
    </style>
</block>
<block name="body">
    <include file="Public:timepicker" />
    <!-- 弹窗插件 -->
    <include file="Public:artdialog" />
    <!-- 表单验证插件 -->
    <include file="Public:validform" />
    <link rel="stylesheet" href="/Public/Admin/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/Public/Admin/ztree/js/jquery-migrate-1.2.1.js"></script>
    <script type="text/javascript" src="/Public/Admin/ztree/js/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="/Public/Admin/ztree/js/jquery.ztree.excheck-3.5.min.js"></script>
    <div class="row"  >
        <div class="col-md-12" >
            <div class="block-web">
                <div class="header">
                    <h3 class="content-header"><if condition="$is_add eq 0">新增<else/>编辑</if>权限组</h3>
                </div>
                <div class="porlets-content">
                    <form class="form-horizontal row-border vform_show" action="{:U('Auth/auth_group_add')}">
                        <table style="table-layout: fixed;width: 100%;">
                            <tr>
                                <td width="380px" style="vertical-align:top;">
                                    <input type="hidden" name="is_add" value="{$is_add}">
                                    <input type="hidden" name="id" value="{$m['id']}">
                                    <input type="hidden" name="rules" id="rules" value="{$m['rules']}">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">权限组名称</label>
                                        <div class="col-sm-8">
                                            <input type="text" name="title" class="form-control"  value="{$m['title']}" datatype="*"  nullmsg="请输入权限组名称！" >
                                            <div class="Validform_checktip"></div>
                                        </div>
                                        <span class="red">*</span>
                                    </div><!--/form-group-->

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">排序</label>
                                        <div class="col-sm-8">
                                            <input type="text" name="sort" class="form-control" value="{$m['sort']|default='0'}" datatype="n" nullmsg="请输入排序">
                                            <div class="Validform_checktip"></div>
                                        </div>

                                        <span class="red">*</span>

                                    </div><!--/form-group-->


                                    <if condition="$is_add eq 1">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">是否启用</label>
                                            <div class="col-sm-9">
                                                <label class="radio-inline">
                                                    <input type="radio"  <if condition="$status eq 1">checked</if> name="status" value="1" id="inlineradio1" >
                                                    <span class="custom-radio"></span> 启用 </label>
                                                <label class="radio-inline">
                                                    <input type="radio"  name="status"  <if condition="$status eq 0">checked</if>  value="0" id="inlineradio2">
                                                    <span class="custom-radio"></span> 禁止 </label>
                                            </div>
                                        </div>
                                        <else/>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">是否启用</label>
                                            <div class="col-sm-9">
                                                <label class="radio-inline">
                                                    <input type="radio"  checked name="status" value="1" id="inlineradio1" >
                                                    <span class="custom-radio"></span> 启用 </label>
                                                <label class="radio-inline">
                                                    <input type="radio"  name="status" value="0" id="inlineradio2">
                                                    <span class="custom-radio"></span> 禁止 </label>
                                            </div>
                                        </div>
                                    </if>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">描述</label>
                                        <div class="col-sm-9">
                                            <textarea name="remark" style="min-height: 75px;width: 100%;">{$m['remark']}</textarea>
                                        </div>
                                        <div class="col-sm-1">
                                            <span class="red"></span>
                                        </div>
                                    </div>
                                </td>
                                <td style="padding-left: 50px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">权限：</label>
                                        <div class="col-sm-9">
                                            <div style="width: 100%;">
                                                <a href="javascript:;" onclick="checkAllTrue()" class="btn btn-success btn-xs">全选</a>&nbsp;
                                                <a href="javascript:;" onclick="checkAllFalse()" class="btn btn-success btn-xs">取消</a>&nbsp;
                                                <a href="javascript:;" onclick="expandAll()" class="btn btn-success btn-xs">展开</a>&nbsp;
                                                <a href="javascript:;" onclick="collapseAll()" class="btn btn-success btn-xs">折叠</a>&nbsp;
                                            </div>
                                            <div style="width: 100%;">
                                                <ul id="treeRule" class="ztree"></ul>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                        <div class="footer" >
                            <button class="btn btn-primary btn-success bt_submit" type="submit">提交</button>
                            <button class="btn btn-default bt_close" type="button" onclick="art.dialog.open.api.close();" >关闭</button>
                        </div>
                    </form>
                </div><!--/porlets-content-->
            </div><!--/block-web-->
        </div><!--/col-md-6-->

    </div>

</block>
<block name="script">
    <script type="text/javascript">
        <if condition="$parent_id neq 0">
                $(function(){
                    $("#parent_id option[value={$parent_id}]").attr("selected", "selected");

                });
        </if>

        <if condition="$is_add eq 1">
                $(function(){
                    $("#parent_id").attr("disabled","disabled");
                });
        </if>


        var setting = {
            view: {
                selectedMulti: false
            },
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        var treeObj;
        function createTree() {
            $.post("{:U('Auth/auth_group_rules_ajax',array('id'=>$m['id']))}",function(resultobj){
                treeObj= $.fn.zTree.init($("#treeRule"), setting, resultobj);
//                treeObj.expandAll(true);
            });



        }

        $(function(){
            createTree();
        });
        function checkAllTrue(){
            treeObj.checkAllNodes(true);
        }
        function checkAllFalse(){
            treeObj.checkAllNodes(false);
        }
        function expandAll(){
            treeObj.expandAll(true);
        }
        function collapseAll(){
            treeObj.expandAll(false);
        }


        $(function () {

            var fromchk = $(".vform_show").Validform({
                tiptype: 2,
                tiptype: function (msg, o, cssctl) {

                    if (!o.obj.is("form")) {

                        if(o.type ==2)
                        {
                            var parent_ele = o.obj.attr('parent_ele');
                            if ( typeof parent_ele === 'undefined' ) {
                                //code
                                var objtip=o.obj.siblings(".Validform_checktip");
                                objtip.removeClass('Validform_wrong');
                            }else{
                                var objtip=o.obj.parent().siblings(".Validform_checktip");
                                objtip.removeClass('Validform_wrong');
                            }
                            objtip.html('');
                        }else{
                            var parent_ele = o.obj.attr('parent_ele');
                            if ( typeof parent_ele === 'undefined' ) {
                                //code
                                var objtip=o.obj.siblings(".Validform_checktip");
                            }else{
                                var objtip=o.obj.parent().siblings(".Validform_checktip");
                            }

                            cssctl(objtip,o.type);
                            objtip.text(msg);
                            showvfmsg('0', msg, 1900);
                        }

                    } else
                    {
                        huoquanxian();
                        $("#submit").attr("disabled",'disabled');
                        $("#submit").html("提交中...");
                        $(".bt_submit").attr("disabled", 'disabled');
                        $(".bt_submit").html("提交中...");
                        showvfmsg("-1", '提交中，请稍后...', 999999);

                    }
                },
                ajaxPost: true,
                tipSweep: true,
                callback: function (data) {
                    if (data.status) {

                        setTimeout(function () {
                            if (data.url == "0") {
                                window.location.reload();
                            } else if (typeof(data.url)!='undefined' && data.url != "") {
                                window.location.href = data.url;
                            }
                        }, 1300);
                    } else {

                    }

                    $("#submit").removeAttr("disabled");
                    $("#submit").html("保 存");
                    $(".bt_submit").removeAttr("disabled");
                    $(".bt_submit").html("提交");
                    var retstatus = data.status == 1 ? "1" : "0";
                    showvfmsg(retstatus, data.info, 1900);
                }

            });

        });

        function huoquanxian(){
            var nodes=treeObj.getCheckedNodes(true);
            var newArrays=new Array();
            for(var  i=0;i<nodes.length;i++){
                newArrays.push(nodes[i].id);
            }
            console.info(newArrays);
            $("#rules").val(newArrays.join(","));
        }
    </script>
</block>